@extends('layouts.public')

@section('head')
    <link rel="stylesheet" href="{{cdn('js/plugins/webuploader/single.css')}}">
@endsection

@section('bodyattr')class="gray-bg"@endsection

@section('body')
    <div class="wrapper wrapper-content">
        <div class="row m-b">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li><a href="{{route('admin.good.goods.comment', $id)}}">评论列表</a></li>
                        <li @if(!isset($user))class="active"@endif><a
                                    href="{{route('admin.good.goods.comment_add',$id)}}">新增</a></li>
                        @if(isset($user))
                            <li class="active"><a href="#">编辑</a></li>
                        @endif
                    </ul>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form action="{{route('admin.good.goods.comment_save')}}" method="post"
                              class="form-horizontal ajaxForm">
                            <input type="hidden" name="goods_id" value="{{$id}}">
                            <input type="hidden" name="id" value="{{$user->id or 0}}"/>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">商品</label>
                                <div class="col-sm-3">
                                    {{$forums->title}}
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">评论</label>
                                <div class="col-sm-3">
                                    <textarea class="form-control" name="content"
                                              @if(isset($user)) value="{{$user->content or ''}}"
                                              @endif  placeholder="请填写评论" required></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">图片</label>
                                <div class="col-sm-10" id="shop_box">
                                    <div id="shop_picker">选择图片</div>
                                    {{--                                    <p>图片用来展示小程序店铺主页，建议尺寸为750px*380px,效果更好</p>--}}
                                    @if(isset($user) && $user->imgs != '')
                                        @foreach(explode(',',$user['imgs']) as $g)
                                            <div class="img-div">
                                                <img src="{{get_file_url($g)}}"/>
                                                <span class="cancel">×</span>
                                            </div>
                                        @endforeach
                                    @endif
                                    <input type="hidden" id="goodcomment" name="imgs" value="{{$user->imgs or ''}}"/>
                                    <input type="hidden" id="goodComment_file_id" name="shopComment_file_id" value=""/>
                                </div>

                            </div>


                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存</button>
                                    <button class="btn btn-white" type="button" id="backBtn">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script src="{{cdn('js/plugins/webuploader/webuploader.nolog.min.js')}}"></script>
    <script src="{{cdn('js/plugins/webuploader/webuploader_public.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            singleUpload({
                _token: '{{csrf_token()}}',
                type_key: 'FT_ONE_RESOURCE',
                item_id: '{{$user->id or 0}}',
                pick: 'shop_picker',
                boxid: 'shop_box',
                file_path: 'goodcomment',
                file_id: 'goodComment_file_id',
                multi: true,
                maximg: 3
            });
            $('#shop_box').find('.img-div>span').click(function () {
                sUploadDel($(this), 'goodcomment');
            });
        });
    </script>
@endsection